package io.renren.modules.psorder.service.impl;

import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import io.renren.modules.psorder.dao.PsOrderDao;
import io.renren.modules.psorder.entity.PsOrderEntity;
import io.renren.modules.psorder.service.PsOrderService;



@Service("psOrderService")
public class PsOrderServiceImpl implements PsOrderService {

	enum RoleType {
		User,Driver
	}

	@Autowired
	private PsOrderDao psOrderDao;
	
	@Override
	public PsOrderEntity queryObject(Long id){
		return psOrderDao.queryObject(id);
	}
	
	@Override
	public List<PsOrderEntity> queryList(Map<String, Object> map){
		return psOrderDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return psOrderDao.queryTotal(map);
	}
	
	@Override
	public void save(PsOrderEntity psOrder){
		psOrderDao.save(psOrder);
	}
	
	@Override
	public void update(PsOrderEntity psOrder){
		psOrderDao.update(psOrder);
	}
	
	@Override
	public void delete(Long id){
		psOrderDao.delete(id);
	}
	
	@Override
	public void deleteBatch(Long[] ids){
		psOrderDao.deleteBatch(ids);
	}

	@Override
	public PsOrderEntity queryByOrderNum(String orderNum) {
		return psOrderDao.queryByOrderNum(orderNum);
	}

	private List<PsOrderEntity> queryPsOrder(Long id,String orderStatus,RoleType roleType) {
		Map<String,Object> param = new HashedMap();
		if (roleType == RoleType.User) {
			param.put("userId",id);
		} else {
			param.put("driverId",id);
		}
		param.put("orderStatus",orderStatus); //"1"表示已完成
		return psOrderDao.queryList(param);
	}

	@Override
	public List<PsOrderEntity> userQueryCompletedPsOrder(Long userId) {
//		return queryPsOrder(userId,"1",RoleType.User);
		return psOrderDao.userQueryCompletedPsOrder(userId);
	}

	@Override
	public List<PsOrderEntity> userQueryOnGoingPsOrder(Long userId) {
//		return queryPsOrder(userId,"0",RoleType.User);
		return psOrderDao.userQueryOnGoingPsOrder(userId);
	}

	@Override
	public List<PsOrderEntity> userQueryCancelPsOrder(Long userId) {
//		return queryPsOrder(userId,"3",RoleType.User);
		return psOrderDao.userQueryCancelPsOrder(userId);
	}

	@Override
	public List<PsOrderEntity> driverQueryOnGoingPsOrder(Long driverId) {
		Map<String,Object> param = new HashedMap();
		param.put("driverId",driverId);

		return psOrderDao.driverQueryOnGoingPsOrder(param);
	}

	@Override
	public List<PsOrderEntity> driverQueryCompletedPsOrder(Long driverId) {
		Map<String,Object> param = new HashedMap();
		param.put("driverId",driverId);
		return psOrderDao.driverQueryEndPsOrder(param);
	}

	@Override
	public List<PsOrderEntity> driverQueryCancelPsOrder(Long driverId) {
		return queryPsOrder(driverId,"3",RoleType.Driver);
	}

	@Override
	public List<PsOrderEntity> driverQueryPushRecords(String driverUser) {
		return psOrderDao.driverQueryPushRecords(driverUser);
	}

	@Override
	public void remindAllAppointPsOrder() {
		//查出所有预约时间-10分钟<=当前时间，即最多提前10分钟通知预约订单即将开始



	}


	//订单导出
	public List<PsOrderEntity> queryListExcel(Map<String, Object> map){
		return psOrderDao.queryListExcel(map);
	}

}
